package com.sample.kokou;

import android.view.View;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import android.widget.TextView;

import android.app.Activity;
import android.os.Bundle;

public class SqliteSampleActivity extends Activity {
    private TextView view;
    private SQLiteDatabase db;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        view = GenericUtil.getView(this, R.id.displayTextView);
        db = (new SampleDBHelper(this)).getReadableDatabase();
    }

    public void displayTable(View v) {
        Cursor c = db.query("people", new String[] {"name", "age"},
                            null, null, null, null, null);
        view.setText("Table contents\n");
        view.append("--------------------------------------\n");
        while (c.moveToNext()) {
            view.append(String.format("%s\t%d\n", c.getString(0), c.getInt(1)));
        }
        c.close();
    }
}